package com.fj.controller;

import com.fj.entity.DevUser;
import com.fj.service.DevUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class DevUserController {

    @Autowired
    private DevUserService devUserService;

    @RequestMapping("/devLogin")
    public String devLogin(HttpServletRequest request,Model model, String devCode, String devPwd){
        if(devCode==null || devCode==""){
            model.addAttribute("code","登录名不能为空");
            return "devlogin";
        }
        if(devPwd==null || devPwd==""){
            model.addAttribute("pwd","密码不能为空");
            return "devlogin";
        }
        DevUser devUser = devUserService.login(devCode);
        if(devUser==null){
            model.addAttribute("devUser","登录名错误或不存在");
            return "devlogin";
        }
        if(!devUser.getDevpassword().equals(devPwd)){
            model.addAttribute("dlpwd","密码错误");
            return "devlogin";
        }
        HttpSession session=request.getSession();
        session.setAttribute("devName",devUser.getDevname());
        return null;
    }
}
